package sw6.admin.parser;

import android.content.Context;
import android.util.Log;
import sw6.admin.database.DatabaseHelper;

public class StoreSettings implements ISettingsParserStrategy {

	private DatabaseHelper db;
	private String appName;
	
	@Override
	public void init(Context context, String appName) {
		this.db = new DatabaseHelper(context);
		this.appName = appName;
	}

	@Override
	public void handleInteger(String varName, int min, int max, int varValue) {
		Log.i("SettingsParser", "Added Integer: " + varName);
		db.insertInteger(appName, varName, varValue, min, max);
	}

	@Override
	public void handleDouble(String varName, double min, double max, double varValue) {
		Log.i("SettingsParser", "Added Double: " + varName);
		db.insertDouble(appName, varName, varValue, min, max);
	}

	@Override
	public void handleBoolean(String varName, boolean varValue) {
		Log.i("SettingsParser", "Added Boolean: " + varName);
		db.insertBoolean(appName, varName, varValue);
	}

	@Override
	public void handleString(String varName, int min, int max, String varValue) {
		Log.i("SettingsParser", "Added String: " + varName);
		db.insertString(appName, varName, varValue, min, max);
	}

	@Override
	public void handleObject(String varName, String type, byte[] varValue) {
		Log.i("SettingsParser", "Added Object: " + varName + " Type: " + type);
		db.insertObject(appName, varName, type, varValue);
	}

	@Override
	public void handleEnumElement(String varName, int varValue) {
		Log.i("SettingsParser", "Added Enum element: " + varName);
		db.insertEnumElement(appName, varName, varValue);
	}

	@Override
	public void handleEnum(String varName, int varValue) {
		Log.i("SettingsParser", "Added Enum: " + varName);
		db.insertEnum(appName, varName, varValue);
	}
	
	@Override
	public void end() {
		db.close();
	}
	
}
